package cn.terminus.web.customer.customcontacts.controller;

import cn.terminus.client.customer.customcontacts.param.*;
import cn.terminus.client.customer.customcontacts.result.CustomContactsResult;
import cn.terminus.client.customer.customcontacts.service.CustomContactsService;
import cn.terminus.result.common.exception.ServiceException;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.result.common.result.TerminusResult;
import cn.terminus.result.common.util.BeanCopyUtils;
import cn.terminus.web.customer.common.AbstractTerminusController;
import cn.terminus.web.customer.customcontacts.form.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * (CustomContacts)控制层
 *
 * @author makejava
 * @version 1.0.0
 * @apiDefine CustomContacts $serviceComment
 * @since 2021-07-08 11:18:41
 */
@RestController
// todo 请修改path
@RequestMapping("/customContacts")
@Api(value = "(CustomContacts)控制层")
public class CustomContactsController extends AbstractTerminusController {
    /**
     * 服务对象
     */
    @Resource
    private CustomContactsService customContactsService;

    /**
     * @api {POST} /customContacts/add 新增
     * @apiVersion 1.0.0
     * @apiGroup CustomContacts
     * @apiName 新增
     * @apiDescription 新增
     * @apiParam (RequestBody) {Long} businessId  租户ID
     * @apiParam (RequestBody) {Long} cboCustomId  客户ID
     * @apiParam (RequestBody) {String} cboCustomContactsphone  联系人电话
     * @apiParam (RequestBody) {Integer} type  类型
     * @apiParam (RequestBody) {String} cboCustomContacts  联系人姓名
     * @apiParam (RequestBody) {String} createUser  create_user
     * @apiParam (RequestBody) {Date} createTime  create_time
     * @apiParam (RequestBody) {String} lastUpdateUser  last_update_user
     * @apiParam (RequestBody) {Date} lastUpdateTime  last_update_time
     * @apiSuccess (Success 200) {String} code    状态码（00000000表示请求成功）
     * @apiSuccess (Success 200) {Boolean} success    成功
     * @apiSuccess (Success 200) {String} message    结果消息
     * @apiSuccess (Success 200) {String} data    结果
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":"[]"}
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ApiOperation(value = "${serviceComment}新增", httpMethod = "POST")
    public TerminusResult<String> add(@RequestBody CustomContactsNewForm form) {
        CustomContactsNewParam param = BeanCopyUtils.copyProperties(form, CustomContactsNewParam.class);
        try {
            return customContactsService.add(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("新增${serviceComment}失败，原因：", e);
            return TerminusResult.fail("11", this.getMessage("11"));
        } catch (Exception e) {
            logger.error("新增${serviceComment}失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }


    /**
     * @api {POST} /customContacts/edit 编辑
     * @apiVersion 1.0.0
     * @apiGroup CustomContacts
     * @apiName 编辑
     * @apiDescription 编辑
     * @apiParam (RequestBody) {Long} id  ID
     * @apiParam (RequestBody) {Long} businessId  租户ID
     * @apiParam (RequestBody) {Long} cboCustomId  客户ID
     * @apiParam (RequestBody) {String} cboCustomContactsphone  联系人电话
     * @apiParam (RequestBody) {Integer} type  类型
     * @apiParam (RequestBody) {String} cboCustomContacts  联系人姓名
     * @apiParam (RequestBody) {String} createUser  create_user
     * @apiParam (RequestBody) {Date} createTime  create_time
     * @apiParam (RequestBody) {String} lastUpdateUser  last_update_user
     * @apiParam (RequestBody) {Date} lastUpdateTime  last_update_time
     * @apiSuccess (Success 200) {String} code    状态码（00000000表示请求成功）
     * @apiSuccess (Success 200) {Boolean} success    成功
     * @apiSuccess (Success 200) {String} message    结果消息
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":true}
     */

    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    @ApiOperation(value = "${serviceComment}编辑", httpMethod = "POST")
    public TerminusResult<Boolean> edit(@RequestBody CustomContactsEditForm form) {
        CustomContactsEditParam param = BeanCopyUtils.copyProperties(form, CustomContactsEditParam.class);
        try {
            return customContactsService.update(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("修改${serviceComment}失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("修改${serviceComment}失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

    /**
     * @api {POST} /customContacts/delete 删除
     * @apiVersion 1.0.0
     * @apiGroup CustomContacts
     * @apiName 删除
     * @apiDescription 删除
     * @apiParam (RequestBody) {String[]} ids  ids
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":true}
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ApiOperation(value = "${serviceComment}删除", httpMethod = "POST")
    public TerminusResult<Boolean> delete(@RequestBody CustomContactsDeleteForm form) {
        CustomContactsDeleteParam param = BeanCopyUtils.copyProperties(form, CustomContactsDeleteParam.class);
        try {
            return customContactsService.delete(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("删除${serviceComment}失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("删除${serviceComment}失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

    /**
     * @api {POST} /customContacts/gets 详情
     * @apiVersion 1.0.0
     * @apiGroup CustomContacts
     * @apiName 详情
     * @apiDescription 详情
     * @apiParam (RequestBody) {String[]} ids  ids
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccess (Success 200) {Object[]} data.datas    列表
     * @apiSuccess (Success 200) {Long} data.datas.id  ID
     * @apiSuccess (Success 200) {Long} data.datas.businessId  租户ID
     * @apiSuccess (Success 200) {Long} data.datas.cboCustomId  客户ID
     * @apiSuccess (Success 200) {String} data.datas.cboCustomContactsphone  联系人电话
     * @apiSuccess (Success 200) {Integer} data.datas.type  类型
     * @apiSuccess (Success 200) {String} data.datas.cboCustomContacts  联系人姓名
     * @apiSuccess (Success 200) {String} data.datas.createUser  create_user
     * @apiSuccess (Success 200) {Date} data.datas.createTime  create_time
     * @apiSuccess (Success 200) {String} data.datas.lastUpdateUser  last_update_user
     * @apiSuccess (Success 200) {Date} data.datas.lastUpdateTime  last_update_time
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":[]}
     */
    @RequestMapping(value = "/gets", method = RequestMethod.POST)
    @ApiOperation(value = "${serviceComment}详情查询", httpMethod = "POST")
    public TerminusResult<List<CustomContactsResult>> gets(@RequestBody CustomContactsGetsForm form) {
        CustomContactsGetsParam param = BeanCopyUtils.copyProperties(form, CustomContactsGetsParam.class);
        try {
            return customContactsService.gets(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("查询${serviceComment}失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("查询${serviceComment}失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

    /**
     * @api {POST} /customContacts/query 查询
     * @apiVersion 1.0.0
     * @apiGroup CustomContacts
     * @apiName 查询
     * @apiDescription 查询
     * @apiParam (RequestBody) {Long} businessId  租户ID
     * @apiParam (RequestBody) {Long} cboCustomId  客户ID
     * @apiParam (RequestBody) {String} cboCustomContactsphone  联系人电话
     * @apiParam (RequestBody) {Integer} type  类型
     * @apiParam (RequestBody) {String} cboCustomContacts  联系人姓名
     * @apiParam (RequestBody) {String} createUser  create_user
     * @apiParam (RequestBody) {Date} createTime  create_time
     * @apiParam (RequestBody) {String} lastUpdateUser  last_update_user
     * @apiParam (RequestBody) {Date} lastUpdateTime  last_update_time
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccess (Success 200) {Object[]} data.datas    列表
     * @apiSuccess (Success 200) {Long} data.datas.id  ID
     * @apiSuccess (Success 200) {Long} data.datas.businessId  租户ID
     * @apiSuccess (Success 200) {Long} data.datas.cboCustomId  客户ID
     * @apiSuccess (Success 200) {String} data.datas.cboCustomContactsphone  联系人电话
     * @apiSuccess (Success 200) {Integer} data.datas.type  类型
     * @apiSuccess (Success 200) {String} data.datas.cboCustomContacts  联系人姓名
     * @apiSuccess (Success 200) {String} data.datas.createUser  create_user
     * @apiSuccess (Success 200) {Date} data.datas.createTime  create_time
     * @apiSuccess (Success 200) {String} data.datas.lastUpdateUser  last_update_user
     * @apiSuccess (Success 200) {Date} data.datas.lastUpdateTime  last_update_time
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":[]}
     */
    @RequestMapping(value = "/query", method = RequestMethod.POST)
    @ApiOperation(value = "${serviceComment}查询", httpMethod = "POST")
    public TerminusResult<List<CustomContactsResult>> query(@RequestBody CustomContactsQueryForm form) {
        CustomContactsQueryParam param = BeanCopyUtils.copyProperties(form, CustomContactsQueryParam.class);
        try {
            return customContactsService.query(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("查询${serviceComment}失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("查询${serviceComment}失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

    /**
     * @api {POST} /customContacts/page 分页查询
     * @apiVersion 1.0.0
     * @apiGroup CustomContacts
     * @apiName 分页查询
     * @apiDescription 分页查询
     * @apiParam (RequestBody) {Long} businessId  租户ID
     * @apiParam (RequestBody) {Long} cboCustomId  客户ID
     * @apiParam (RequestBody) {String} cboCustomContactsphone  联系人电话
     * @apiParam (RequestBody) {Integer} type  类型
     * @apiParam (RequestBody) {String} cboCustomContacts  联系人姓名
     * @apiParam (RequestBody) {String} createUser  create_user
     * @apiParam (RequestBody) {Date} createTime  create_time
     * @apiParam (RequestBody) {String} lastUpdateUser  last_update_user
     * @apiParam (RequestBody) {Date} lastUpdateTime  last_update_time
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccess (Success 200) {long} data.pageSize    分页大小
     * @apiSuccess (Success 200) {long} data.currentPage    当前页
     * @apiSuccess (Success 200) {long} data.totalPages    总页数
     * @apiSuccess (Success 200) {long} data.totalRows    总记录数
     * @apiSuccess (Success 200) {long} data.minRowNumber    当页起始行号
     * @apiSuccess (Success 200) {long} data.maxRowNumber    当页最大行号
     * @apiSuccess (Success 200) {Object[]} data.datas    列表
     * @apiSuccess (Success 200) {Long} data.datas.id  ID
     * @apiSuccess (Success 200) {Long} data.datas.businessId  租户ID
     * @apiSuccess (Success 200) {Long} data.datas.cboCustomId  客户ID
     * @apiSuccess (Success 200) {String} data.datas.cboCustomContactsphone  联系人电话
     * @apiSuccess (Success 200) {Integer} data.datas.type  类型
     * @apiSuccess (Success 200) {String} data.datas.cboCustomContacts  联系人姓名
     * @apiSuccess (Success 200) {String} data.datas.createUser  create_user
     * @apiSuccess (Success 200) {Date} data.datas.createTime  create_time
     * @apiSuccess (Success 200) {String} data.datas.lastUpdateUser  last_update_user
     * @apiSuccess (Success 200) {Date} data.datas.lastUpdateTime  last_update_time
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":[]}
     */
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    @ApiOperation(value = "${serviceComment}分页查询", httpMethod = "POST")
    public TerminusResult<TerminusPageAble<CustomContactsResult>> page(@RequestBody CustomContactsQueryForm form) {
        CustomContactsQueryParam param = BeanCopyUtils.copyProperties(form, CustomContactsQueryParam.class);
        try {
            TerminusPageInfo page = new TerminusPageInfo(form.getCurrentPage(), form.getRowsOfPage());
            return customContactsService.page(param, page, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("分页查询${serviceComment}失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("分页查询${serviceComment}失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

}
